/**
 * 
 */
package com.zhiteng.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhiteng.entity.School;
import com.zhiteng.entity.Teacher;
import com.zhiteng.service.SchoolService;
import com.zhiteng.service.TeacherService;
import com.zhiteng.utils.common.ZTResult;

/**  
* <p>Title: SchoolController.java</p>  
* <p>Description: </p>  
* @author dragon  
* @date 2018年11月15日  
* @version 1.0  
*/
@Controller
@RequestMapping("/school")
public class SchoolController {
	@Autowired
	private SchoolService schoolService;
	@Autowired
	private TeacherService teacherService;
	
	/**
	 * 
	* @Title: getAllSchool  
	* @Description: 获取腾讯智慧校园所有的学校 
	* @return ZTResult<List<School>>   
	* @throws
	 */
	@RequestMapping("/getAllSchool")
	@ResponseBody
	public ZTResult<List<School>> getAllSchool(){
		List<School> schoolList = schoolService.getAllSchool();
		return ZTResult.result(0, "查询成功", schoolList);
	}
	
	/**
	 * 
	* @Title: getAllTeacher  
	* @Description: 根据学校名称查询该校所有在校教师
	* @param schoolName
	* @return ZTResult<List<School>>   
	* @throws
	 */
	@RequestMapping("/getAllTeacher")
	@ResponseBody
	public ZTResult<List<Teacher>> getAllTeacher(@RequestParam(name="schoolName")String schoolName){
		if(StringUtils.isBlank(schoolName)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		List<Teacher> teacherList = teacherService.queryAllTeacherBySchoolName(schoolName);
		return ZTResult.result(0, "查询成功", teacherList);
	}
	
	/**
	 * 
	* @Title: getAllTeacher  
	* @Description: 根据学校id查询该校所有在校教师
	* @param schoolId
	* @return ZTResult<List<School>>   
	* @throws
	 */
	@RequestMapping("/getAllTeacherBySchoolId")
	@ResponseBody
	public ZTResult<List<Teacher>> getAllTeacherBySchoolId(@RequestParam(name="schoolId")String schoolId){
		if(StringUtils.isBlank(schoolId)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		School school = schoolService.querySchoolById(schoolId);
		List<Teacher> teacherList = teacherService.queryAllTeacherBySchoolName(school.getName());
		return ZTResult.result(0, "查询成功", teacherList);
	}
	
	/**
	 * 
	* @Title: getTeacherByName  
	* @Description: 根据教师名称查询教师信息 
	* @param teacherName
	* @param schoolName
	* @return ZTResult<List<Teacher>>   
	* @throws
	 */
	@RequestMapping("/getTeacherByName")
	@ResponseBody
	public ZTResult<List<Teacher>> getTeacherByName(@RequestParam(name="teacherName")String teacherName,
			@RequestParam(name="schoolName")String schoolName){
		if(StringUtils.isAnyBlank(teacherName,schoolName)) {
			return ZTResult.result(1,"查询失败，请检查参数");
		}
		List<Teacher> teacherList = teacherService.queryTeacherByTeacherNameAndSchoolName(schoolName, teacherName);
		return ZTResult.result(0, "查询成功", teacherList);
	}
}
